<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>解决margin塌陷</title>
  <style>
    div.father {
      width: 200px;
      height: 200px;
      background-color: rgb(219, 68, 101);
      margin-left: 100px;
      margin-top: 100px;
      position: absolute;
    }

    div.father div.son {
      width: 100px;
      height: 100px;
      background-color: rgb(56, 248, 207);
      margin-left: 50px;
      margin-top: 50px;
    }
  </style>
</head>

<body>

  <!-- margin塌陷的效果就是 当父元素有margin的时候，子元素内部的上margin如果比父元素的margin小，那么就不会生效 -->
  <!-- 给父元素添加下面的属性，可以触发bfc，让子元素的margin生效 -->
  <!-- float属性为left/right
overflow为hidden/scroll/auto
position为absolute/fixed
display为inline-block/table-cell/table-caption -->
  <div class="father">
    <div class="son"></div>
  </div>
</body>

</html>